﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Compilex.Syntatic;

namespace Compilex.CodeGeneration
{
    public class ImprimexIntex
    {
        protected CodeGenerator Generator { get; set; }
        public ImprimexIntex(CodeGenerator generator)
        {
            this.Generator = generator;
        }

        public void Invoke()
        {
            Generator.Ops.Comment("imprimex_intex");
            const int offset = 0x30;
            Generator.Ops.LoadGlobalVariable(LibraryFunctions.ParamName);
            Generator.Ops.Add(offset);
            Generator.CodeBuilder.AppendLine("PD /100");
        }



        public static string ImprimexFullIntex()
        {

            return @"funcex imprimex_full_intex(intex n):
                     intex base = 1; intex offset = 0;
                  
                        sex n < 0:
                            imprimex_intex(0-3);
                            n = 0-n;
                        finex sex;

                        sex n == 0:
                            imprimex_intex(0);
                            retornex;
                        finex sex;
    
                     enquantex n >= base:
                            base = base * 10;    
                     finex enquantex;
                    
                     enquantex base > 1:
                        base = base/10;
                        offset = n/base;  
                        imprimex_intex(offset); 
                        n = n - (offset*base); 
                     finex enquantex;


                     finex funcex;
                    
";

        }

    }
}
